package cn.glc.daily.life.web.convert;

import cn.glc.daily.life.model.to.UserRoleTo;
import cn.glc.daily.life.model.vo.jwt.auth.JwtUserDetailVo;
import cn.glc.daily.life.model.vo.user.UserVo;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.stream.Collectors;

/**
 * @author simon
 * @date 2021/5/13 14:25
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@Mapper
public interface JwtUserConvert {

    JwtUserConvert INSTANCE = Mappers.getMapper(JwtUserConvert.class);

    /**
     * jwt 用户信息交互
     *
     * @param userVo
     * @return
     */
    default JwtUserDetailVo userVo2JwtUserDetail(UserVo userVo) {
        return JwtUserDetailVo.builder()
                .uid(userVo.getUid())
                .nickName(userVo.getNickName())
                .name(userVo.getUserInfoTo().getName())
                .sex(userVo.getUserInfoTo().getSex())
                .status(userVo.getStatus())
                .flag(userVo.getFlag())
                .userRole(userVo.getUserRoleToList().stream().map(UserRoleTo::getRoleId).collect(Collectors.toList()))
                .build();
    }
}
